<template>
    <div class="loanApplyMng applyList">
        <rui-page :defines="defines" :has-card-box="false" class="loanApply">
            <!-- 查询条件 -->
            <!--  isApplyQuery: 进件系统UI版式 searchFormOptions只能传一行      -->
            <rui-query :label-width="100"
                       isApplyQuery
                       ref="loanApplyForm"
                       :query="queryData"
                       :query-rows="searchFormOptions"
                       :more-rows="searchMoreOptions">
                <template slot="key" slot-scope="{ key,item,data }">
                    <Input prefix="ios-search" v-model="data[key]" @keyup.enter.native="queryFormData"
                           placeholder="客户姓名、申请编号"/>
                </template>
                <template slot="applyQueryHead">
                    <Button type="primary" size="default"
                            v-if="username!='admin'&&$store.getters.permissions['new-add-apply']"
                            :disabled="isHide" @click="jumpToIndex">
                        <p style="font-size: 12px;">新增进件申请</p>
                    </Button>
                </template>
            </rui-query>
            <div class="table-card">
                <div class="btn-status flex flex-between">
                    <div class="loanApplyBtn">
                        <template v-for="(item,index) in loanApplyBtns">
                            <Button :key="index" :class="activeBtn === item.key ? 'activeBtn btn' :'btn'" size="default"
                                    @click="applyStatusQuery(item.key)">{{item.title}}
                            </Button>
                        </template>
                    </div>
                    <span style="color: #FF0010;">
<!--                可用加急次数：{{ count }}-->
            </span>
                </div>
                <rui-table
                    :defineId="'loanApplyMngDefine'"
                    :fixedRight="['action']"
                    :showIndex="false"
                    :select="false"
                    :columns="loanApplyColumns"
                    :slots="[{key:'action',slot:'action'},{key:'applyNo',slot:'applyNo'},{key:'applyStatus',slot: 'applyStatus'},{key:'createBy',slot: 'createBy'}]"
                    @loadDatas="queryData"
                    ref-query="loanApplyForm"
                    ref="loanApplyTable"
                    :border="false"
                    :fixedLeft="['applyNo']"
                >
                    <template slot-scope="{ row,  index, }" slot="applyNo">
                        <a v-if="row.applyStatus=='00'&&row.custName=='未录入'"
                           style="color:#3086eb;cursor: pointer;" @click.prevent="skipDetail(row)">
                            {{row.applyNo}}
                        </a>
                        <a v-else-if="row.applyStatus!='00'" style="color:#3086eb;cursor: pointer;"
                           @click.prevent="skipDetail(row)">
                            {{row.applyNo}}
                        </a>
                        <a v-else-if="row.applyStatus=='00'" style="color:#3086eb;cursor: pointer;"
                           @click.prevent="skipDetail(row)">
                            {{row.applyNo}}
                        </a>
                    </template>
                    <template slot-scope="{ row,  index, }" slot="createBy">
                        <Badge>{{row.sellerRealName}}({{row.createBy}})</Badge>
                    </template>
                    <template slot-scope="{ row, index, }" slot="applyStatus">
                        <Badge v-if="row.applyStatus=='00'" text="草稿" color="#999"/>
                        <Badge v-if="row.applyStatus=='01'" text="已提交" color="#999"/>
                        <Badge v-if="row.applyStatus=='02'" text="待审核" color="#999"/>
                        <Badge v-if="row.applyStatus=='03'" text="审核中" color="#999"/>
                        <Badge v-if="row.applyStatus=='04'" text="家访中" color="#999"/>
                        <Badge v-if="row.applyStatus=='05'" text="修订-暂停" color="#e6a23c"/>
                        <Badge v-if="row.applyStatus=='06'" text="修订-回复" color="#999"/>
                        <Badge v-if="row.applyStatus=='07'" text="撤销" color="#999"/>
                        <Badge v-if="row.applyStatus=='08'" text="核准" color="#67c23a"/>
                        <Badge v-if="row.applyStatus=='09'" text="附条件核准" color="#e6a23c"/>
                        <Badge v-if="row.applyStatus=='10'" text="拒绝" color="#f56c6c"/>
                        <Badge v-if="row.applyStatus=='11'" text="取消" color="#f56c6c"/>
                        <Badge v-if="row.applyStatus=='12'" text="复议补充资料" color="#e6a23c"/>
                        <Badge v-if="row.applyStatus=='13'" text="撤回待处理" color="#e6a23c"/>
                    </template>
                    <template slot="action" slot-scope="{ row }">
                        <Dropdown :transfer="true" class="btn-no-border" transfer-class-name="btn-no-border btn-hover-bg">
                            <Button type="primary" ghost>
                                更多
                            </Button>
                            <ButtonGroup slot="list" size="default" vertical>
                                <!--管理员不可以发起进件和预审批，不可以发起编辑、复议、撤回等功能，可实现转单、加急即可-->
                                <Button type="default" @click="deleteOrderInfo(row)" size="default"
                                        v-if="$store.getters.permissions['apply-del-order']&&row.applyStatus==='00'&&(username==row.applyReporter||typeof (row.applyReporter)=='undefined')">
                                    删除
                                </Button>
                                <Button type="default" @click="callBack(row)" size="default"
                                        v-if="$store.getters.permissions['apply-withdraw-order']&&(row.applyStatus==='01'||row.applyStatus==='02'||row.applyStatus==='03'
                                      ||row.applyStatus==='04')&&username==row.applyReporter">
                                    撤回
                                </Button>
                                <Button type="default" @click="edit(row)" size="default"
                                        v-if="$store.getters.permissions['apply-edit-order']&&(row.applyStatus==='00'||row.applyStatus==='05'||row.applyStatus==='12'||row.applyStatus==='13')
                                              &&(username==row.applyReporter||typeof (row.applyReporter)=='undefined')">
                                    编辑
                                </Button>
                                <Button type="default"
                                        v-if="(row.applyStatus==='05')&&(username==row.applyReporter||typeof (row.applyReporter)=='undefined')"
                                        @click="applyCancel(row)">撤销
                                </Button>
                                <Button type="default" @click="transfers(row)"
                                        size="default"
                                        v-if="$store.getters.permissions['apply-transfer-order']&&(row.applyStatus==='00'||row.applyStatus==='05'||row.applyStatus==='09')
                                              &&(username==row.applyReporter||typeof (row.applyReporter)=='undefined')&& (row.createBy===username||userPower.userManage=='9')">
                                    转单
                                </Button>
                                <Button type="default" @click="reconsider(row)"
                                        size="default"
                                        v-if="row.applyStatus==='10'&&username==row.applyReporter&&$store.getters.permissions['apply-reconsider-order']"
                                        :disabled="row.isReconsider=='yes'">
                                    复议
                                </Button>
                                <!--                                <Button type="default"  @click="urgent(row)" size="default"-->
                                <!--                                        v-if="$store.getters.permissions['apply-urgent-order']&&row.applyStatus==='02'&&(username==row.applyReporter||userPower.userManage=='9')"-->
                                <!--                                        :disabled="count==0||row.isUrgent=='yes'">-->
                                <!--                                    加急-->
                                <!--                                </Button>-->
                                <Button type="default" @click="copy(row)" size="default"
                                        v-if="$store.getters.permissions['apply-copy-order']&&username!=='admin'">
                                    复制
                                </Button>
                                <Button type="default" @click="afterLoanAssertChange(row)"
                                        size="default"
                                        v-if="$store.getters.permissions['apply-change-assets']&&row.applyStatus==='08'&&username==row.applyReporter">
                                    资产变更
                                </Button>
                                <Button type="default" @click="checkNotice(row)" size="default"
                                        v-if="(row.applyStatus=='04'&&row.applyStatus=='09')&&username==row.applyReporter">
                                    核准通知书下载
                                </Button>
                                <Button type="default" @click="jumpToConditionApproval(row)" size="default"
                                        v-if="row.applyStatus=='09'&&username==row.applyReporter">
                                    附条件核准
                                </Button>
                            </ButtonGroup>
                        </Dropdown>
                    </template>
                </rui-table>
                <Spin size="large" fix v-if="loading"></Spin>
            </div>
            <!-- add by sijun.yu 2020-5-20 复议操作 -->
            <Modal v-model="reconsiderModalVisible"
                   :width="800"
                   :mask-closable="false"
            >
                <rui-form :form-options="reconsiderFormOptions"
                          :read-only="false"
                          ref="reconsiderForm">
                </rui-form>
                <div class="pr uploadecn" style="margin-left: 85px;">
                    <span>复议资料:</span>
                    <single-upload ref="singleUpload" :imgtype="imgtype"></single-upload>
                </div>
                <div slot="footer">
                    <Button type="text" @click="reconsiderModalVisible=false">取消</Button>
                    <Button type="primary" @click="reconsiderSubmit">确定</Button>
                </div>
            </Modal>
            <!-- add by sijun.yu 2020-5-21 加急操作 -->
            <Modal v-model="urgentModalVisible"
                   :width="800"
                   :mask-closable="false">
                <rui-form :form-options="urgentFormOptions"
                          :read-only="false"
                          ref="urgentForm">
                </rui-form>
                <div slot="footer">
                    <Button type="text" @click="urgentModalVisible=false">取消</Button>
                    <Button type="primary" @click="urgentSubmit">确定</Button>
                </div>
            </Modal>
            <!-- add by sijun.yu 2020-5-22 撤回操作 -->
            <Modal v-model="backModalVisible"
                   :width="800"
                   :mask-closable="false">
                <rui-form :form-options="backFormOptions"
                          :read-only="false"
                          ref="backForm">
                </rui-form>
                <div slot="footer">
                    <Button type="text" @click="backModalVisible=false">取消</Button>
                    <Button type="primary" @click="backSubmit">确定</Button>
                </div>
            </Modal>
            <!-- add by sijun.yu 2020-5-23 转单操作 -->
            <Modal v-model="transferModalVisible"
                   :title="transferTitle"
                   :width="1100"
                   :mask-closable="false">
                <rui-query :label-width="120"
                           ref="transferForm"
                           :query="transferData"
                           :query-rows="transferQueryFormOptions">
                </rui-query>
                <Button @click.native="refreshUserData" icon="ios-refresh">刷新</Button>
                <rui-table :defineId="'loanApplyMngDefine'"
                           :showIndex="false"
                           :slots="[{key:'action',slot:'action'}]"
                           :columns="transferTableColumns"
                           @loadDatas="transferData"
                           ref-query="transferForm"
                           ref="transferTable">
                    <template slot="action" slot-scope="{ row }">
                        <Button type="primary" @click.native="transferSubmit(row)">转单</Button>
                    </template>
                </rui-table>
                <div slot="footer">
                    <Button type="primary" @click.native="transferModalVisible=false">返回</Button>
                </div>
            </Modal>
        </rui-page>
    </div>
</template>
<script>
    import loanApplyMngDefine from "../../api/order-mng/loanApplyMngDefine";
    import {
        applyCancel,
        deleteOrderInfo,
        getLoanApplyList,
        getTransferUser,
        saveBack,
        saveCopy,
        saveReconsiderCaseSubmit,
        saveUrgent,
        sendForCallBackCaseSubmit,
        sendForEmergencyCaseSubmit,
        transferData
    } from "../../api/order-mng/loanApplyMngApi";
    import {getUserInfo} from "../../../basic/api/admin/user";
    import {deepClone} from "../../../../libs/utils/ObjectClone";
    import {saveAssertData} from "../../api/apply-report/personal/common";
    import {getOrderInfo, updateBackTaskIsOpen} from '_p/afs-apply/api/apply-report/personal/businessOption.js';
    import SingleUpload from "@/components/single-upload"
    import {getUserPower} from "_p/afs-apply/api/apply-admin/role/role";

    export default {
        name: "loanApplyMng",
        computed: {
            defines() {
                return [{id: "loanApplyMngDefine", fields: loanApplyMngDefine}];
            }
        },
        mounted() {
            let obj = this.afs.getPageParams(this);
            if (obj) {
                if (obj.flag == "home") {
                    if (obj.applyStatusList) {
                        this.applyStatusIndexQuery(obj.applyStatusList);
                    }
                } else {
                    this.refresh();
                }
            } else {
                this.refresh();
            }
            this.initGteUserInfo();
            // 获取用户登录权限
            this.getUserPower();
        },
        data() {
            return {

                userPower: {
                    userManage: '',
                    userId: '',
                    newApplyPower: '',
                    odlApplyPower: '',
                    newAccountPower: '',
                    oldAccountPower: ''
                },
                createByAndName: '',
                applyStatus: '',
                isUrgent: false,
                isReconsider: false,
                dropDownContent: '更多筛选',
                drop: false,
                dropDownIcon: "ios-arrow-down",
                activeBtn: null, //订单状态按钮
                loanApplyBtns: [
                    {key: null, title: '全部'},
                    {key: '00', title: '草稿'},
                    {key: 'APPLY_STATUS_PRE_DEAL', title: '待处理'},
                    //     <!--修订暂停-->
                    //     <!--修订回复06-->
                    {key: 'APPLY_STATUS_PENDING', title: '待审核'},
                    {key: '08', title: '核准'},
                    //     <!--核准08,附条件核准09-->
                    {key: '10', title: '拒绝'},// <!--10拒绝-->
                ],
                formData: {},
                tableHead: [],
                businessType: '',
                urgentName: "加急",
                isHide: false,
                // 管理员不可以发起进件和预审批，不可以发起编辑、复议、撤回等功能，可实现转单、加急即可
                transferTitle: '转单界面',
                imgtype: "reconsiderApply",
                applyNo: '',
                deptId: '',//部门id
                transferDatas: {},//查询转单人员条件
                roleCode: [],//
                roleCodes: '',
                username: '',
                userRealName: '',
                disable: false,
                count: 0,
                reconsiderModalVisible: false,
                urgentModalVisible: false,
                backModalVisible: false,
                transferModalVisible: false,
                loading: false,
                pageData: {
                    pageNumber: 1,
                    pageSize: 10,
                    total: 0
                },
                searchStatus: {
                    pageNumber: 1,
                    pageSize: 10,
                    condition: {
                        applyStatusList: []
                    }
                },
                //列表显示字段
                loanApplyColumns: [
                    'custName', 'applyNo', 'businessType', 'carType', 'carNature', 'intoFirstDate', 'riskPassDate', 'applyStatus', 'recordRemarks', 'createBy', 'action'
                ],
                searchFormOptions: [
                    {
                        defineId: "loanApplyMngDefine",
                        fields: ["key"],
                        slots: [{key: 'key', slotName: 'key'}]
                    },
                ],
                searchMoreOptions: [
                    {
                        defineId: "loanApplyMngDefine",
                        fields: ["applyNo", "custName", "businessType", "applyDate", "carType", "carNature", "operateWay", "affiliatedWay", "applyStatus"]
                    }
                ],
                //复议页面
                reconsiderFormOptions: [
                    {
                        isGroup: false,
                        groupName: '复议页面',
                        grids: [
                            {defineId: "loanApplyMngDefine", fields: ["reconsiderReason"]}
                        ]
                    }
                ],
                //加急页面
                urgentFormOptions: [
                    {
                        isGroup: false,
                        groupName: '加急页面',
                        grids: [
                            {defineId: "loanApplyMngDefine", fields: ["urgentReason"]}
                        ]
                    }
                ],
                //撤回
                backFormOptions: [
                    {
                        isGroup: false,
                        groupName: '撤回页面',
                        grids: [
                            {defineId: "loanApplyMngDefine", fields: ["backReason"]}
                        ]
                    }
                ],
                //转单
                transferQueryFormOptions: [
                    {
                        defineId: "loanApplyMngDefine",
                        fields: ["userRealName"]
                    }
                ],
                transferTableColumns: [
                    'userRealName', 'username', 'phone', 'action'
                ],
            }
        },
        watch: {
            '$route'(to, from) {
                if (from.path.indexOf("report-edit") > -1) {
                    this.refresh();
                } else if (from.path.indexOf("index") > -1) {
                    this.refresh();
                } else if (from.path.indexOf("conditionsApprove") > -1) {
                    this.refresh();
                }
            }
        },
        components: {
            SingleUpload
        },
        methods: {
            //撤销
            applyCancel(row) {
                this.$Modal.confirm({
                    title: '确认撤销',
                    content: '您确认要撤销编号为:' + row.applyNo + '的订单?',
                    onOk: () => {
                        let params = {
                            applyNo: row.applyNo
                        }
                        applyCancel(params).then(res => {
                            if (res.code === '0000') {
                                this.$Message.success("撤销成功");
                            }
                        });
                    }
                })
            },
            //新增进件申请跳转
            jumpToIndex() {
                this.afs.newTab(this, 'projects/afs-apply/pages/apply-report/personal/index', '申请进件', 'ios-add',
                    {flag: "new"}, 'index' + "-new", [], true);
            },
            //删除订单--草稿状态下
            deleteOrderInfo(row) {
                this.$Modal.confirm({
                    title: "确认删除",
                    content: "您确认要删除编号为" + row.applyNo + "的订单?",
                    onOk: () => {
                        deleteOrderInfo(row).then(res => {
                            if (res.code === '0000') {
                                this.$Message.success("删除成功");
                                this.refresh();
                            }
                        })
                    },
                })
            },
            //查询资产变更次数
            //核准通知书下载
            checkNotice() {
            },
            //跳转附条件核准
            jumpToConditionApproval(row) {
                this.afs.newTab(this, 'projects/afs-apply/pages/apply-report/conditions-approve/conditionsApprove', '附条件核准', 'ios-add',
                    {applyNo: row.applyNo}, 'conditionsApprove' + row.applyNo, [], true);
            },
            //贷前资产变更，点击跳转资产变更
            afterLoanAssertChange(row) {
                let params = {
                    applyNo: row.applyNo,
                }
                //跳转时，数据留痕
                saveAssertData(params).then(res => {
                    if (res.code === '0000') {
                        if (res.data === '0002') {
                            this.$Message.error("该订单已经放款，无法进行资产变更")
                            return;
                        } else if (res.data === '0003') {
                            this.$Message.error("资产变更核准已超过20天,不允许发起资产变更")
                            return;
                        } else if (res.data === '0004') {
                            this.$Message.error("资产变更请求审批中,不允许发起资产变更")
                            return;
                        } else if (res.data === '0005') {
                            this.$Message.error("无权查看")
                            return;
                        } else if (res.data === '0001') {
                            this.$Message.error("资产变更次数不可超过两次")
                            return;
                        } else if (res.data === '0006') {
                            this.$Message.error("合同取消订单，不可发起资产变更")
                            return;
                        } else if (res.data === '0007') {
                            this.$Message.error("合同订单审核中，不可发起资产变更")
                            return;
                        } else {
                            this.afs.newTab(this, 'projects/afs-apply/pages/apply-report/assert-change/assertChange', '资产变更', 'ios-add',
                                {applyNo: row.applyNo, assertId: res.data}, 'assertChange' + row.applyNo, [], true);
                        }
                    }
                });

            },
            //如果加急次数用完，置灰按钮
            urgentCount() {
                this.count--;
                if (this.count === 0) {
                    this.disable = true;
                }
            },
            //申请状态查询
            applyStatusQuery(v) {
                this.activeBtn = v;
                if (v == 'APPLY_STATUS_PENDING') {
                    this.searchStatus.condition.applyStatusList = ['01', '02', '03', '06'];
                } else if (v == undefined) {
                    this.searchStatus.condition.applyStatusList = null;
                } else if (v == "APPLY_STATUS_PRE_DEAL") {
                    this.searchStatus.condition.applyStatusList = ['05', '09', '12', '13'];
                } else {
                    this.searchStatus.condition.applyStatusList = [v];
                }
                this.applyStatus = '';
                this.searchStatus.pageSize = this.pageData.pageSize;
                this.searchStatus.pageNumber = this.pageData.pageNumber;
                console.log(this.searchStatus, "申请状态查询")
                getLoanApplyList(this.searchStatus).then(res => {
                    if (res.code === "0000") {
                        let {records, total} = res.data.loanList;
                        if (res.data.surplusNumbers > 0) {
                            this.count = res.data.surplusNumbers;
                        }
                        this.$refs.loanApplyTable.updateTableData(records, total);
                        let records1 = res.data.loanList.records;
                        for (let i = 0; i < records1.length; i++) {
                            if (records1[i].custName == '' || records1[i].custName == null || typeof (records1[i].custName) == 'undefined') {
                                records1[i].custName = '未录入'
                            }
                        }
                    }
                });
            },
            applyStatusIndexQuery(v) {
                this.activeBtn = v;
                this.searchStatus.condition.applyStatusList = [v];
                this.searchStatus.pageSize = this.pageData.pageSize;
                this.searchStatus.pageNumber = this.pageData.pageNumber;
                console.log(this.searchStatus, "另一个")
                getLoanApplyList(this.searchStatus).then(res => {
                    if (res.code === "0000") {
                        let {records, total} = res.data.loanList;
                        if (res.data.surplusNumbers > 0) {
                            this.count = res.data.surplusNumbers;
                        }
                        this.$refs.loanApplyTable.updateTableData(records, total);
                        let records1 = res.data.loanList.records;
                        for (let i = 0; i < records1.length; i++) {
                            if (records1[i].custName == '' || records1[i].custName == null || typeof (records1[i].custName) == 'undefined') {
                                records1[i].custName = '未录入'
                            }
                        }
                    }
                });
            },
            queryFormData() {
                this.$refs['loanApplyTable'].reloadData();
                // this.queryData(this.$refs.loanApplyForm.getFormData())
            },
            //多条件分页查询
            queryData(queryData) {
                if (typeof queryData.condition.applyDate != "undefined") {
                    let applyDateStart = queryData.condition.applyDate[0];
                    let applyDateEnd = queryData.condition.applyDate[1];
                    queryData.condition.applyDateStart = applyDateStart;
                    queryData.condition.applyDateEnd = applyDateEnd;
                }
                if (typeof this.activeBtn === "undefined") {
                    console.log(2, 'activeBtn_undefined')
                    queryData.condition.applyStatusList = this.searchStatus.condition.applyStatusList;
                } else if (queryData.condition.applyStatus !== '' && queryData.condition.applyStatus != undefined) {
                    console.log(3)
                    this.applyStatus = queryData.condition.applyStatus
                    queryData.condition.applyStatus = this.applyStatus;
                    this.searchStatus.condition.applyStatusList = [];
                } else if (this.activeBtn == 'APPLY_STATUS_PRE_DEAL') {
                    console.log('APPLY_STATUS_PRE_DEAL')
                    queryData.condition.applyStatusList = ['05', '09', '12'];
                } else if (this.activeBtn == 'APPLY_STATUS_PENDING') {
                    queryData.condition.applyStatusList = ['01', '02', '03', '06'];
                    console.log('APPLY_STATUS_PENDING')
                } else if (queryData.condition.applyStatusList != null) {
                    console.log(6)
                    queryData.condition.applyStatusList = queryData.condition.applyStatusList;
                } else {
                    queryData.condition.applyStatus = this.activeBtn;
                }
                console.log(queryData, "多条件查询", this.activeBtn)
                getLoanApplyList(queryData).then(res => {
                    if (res.code === "0000") {
                        let {records, total} = res.data.loanList;
                        if (res.data.surplusNumbers > 0) {
                            this.count = res.data.surplusNumbers;
                        }
                        this.$refs.loanApplyTable.updateTableData(records, total);
                        let records1 = res.data.loanList.records;
                        for (let i = 0; i < records1.length; i++) {
                            if (records1[i].custName == '' || records1[i].custName == null || typeof (records1[i].custName) == 'undefined') {
                                records1[i].custName = '未录入'
                            }
                        }
                    }
                });
            },
            //初始化获得用户信息
            initGteUserInfo() {
                var role = new Set();
                var roleCodeArr = new Set(['ROLE_APPLY', 'ROLE_XCAPPLY']);
                getUserInfo().then(res => {
                    if (res.code === '0000') {
                        let userExtInfo = res.data.userExtInfo;
                        let roles = deepClone(userExtInfo.roles)
                        roles.forEach(res => {
                            //if roleCode has a same code with roleCodeArr
                            if (roleCodeArr.has(res.roleCode)) {
                                let roleTypeTemp = res.roleTypeTemp;
                                roleTypeTemp[0] ? role.add(roleTypeTemp[0]) : ''
                                roleTypeTemp[1] ? role.add(roleTypeTemp[1]) : ''
                            }
                        });
                        //oldCar for oldCar
                        //newCar for newCar
                        role.has("newCar") ? (this.roleCode.push('ROLE_XCAPPLY')) : '';
                        role.has("oldCar") ? (this.roleCode.push('ROLE_APPLY')) : ''
                        let sysUser = res.data.sysUser;
                        this.deptId = deepClone(sysUser.deptId);
                        this.username = sysUser.username;
                    }
                })
            },
            //查询可转单人员--roleCode,deptId,username
            transferData(transferData) {
                if (this.businessType == '01') {
                    this.businessType = 'newCar';
                    if (this.roleCode.length > 0) {
                        for (let i = 0; i < this.roleCode.length; i++) {
                            if (this.roleCode[i] === "ROLE_XCAPPLY") {
                                this.roleCodes = "ROLE_XCAPPLY";
                            }
                        }
                    }
                } else if (this.businessType == '02') {
                    this.businessType = 'oldCar';
                    if (this.roleCode.length > 0) {
                        for (let i = 0; i < this.roleCode.length; i++) {
                            if (this.roleCode[i] === "ROLE_APPLY") {
                                this.roleCodes = "ROLE_APPLY";
                            }
                        }
                    }
                }
                this.userRealName = transferData.condition.userRealName;
                this.transferDatas = {
                    roleCode: this.roleCodes,
                    deptId: this.deptId,
                    username: this.username,
                    phone: transferData.condition.phone,
                    userRealName: this.userRealName,
                    businessType: this.businessType
                };
                transferData = this.transferDatas;
                getTransferUser(transferData).then(res => {
                    if (res.code === '0000') {
                        let records = res.data;
                        let total = res.data.length;
                        this.$refs.transferTable.updateTableData(records, total);
                    }
                })
            },
            skipDetail(row) {
                this.afs.newTab(this, 'projects/afs-apply/pages/apply-report/personal/index', '申请进件', 'ios-add',
                    {applyNo: row.applyNo, diffType: "details"}, 'apply-report-detail' + row.applyNo, [], true);
            },
            edit(row) {
                if (row.applyStatus == '00') {
                    if (row.businessType == '01') {
                        // 我是新车
                        if (this.userPower.newApplyPower != '0') {
                            this.$Message.warning("暂无权限编辑！");
                            return;
                        }
                    }
                    if (row.businessType == '02') {
                        // 我是新车
                        if (this.userPower.odlApplyPower != '0') {
                            this.$Message.warning("暂无权限编辑！");
                            return;
                        }
                    }
                }
                //如果有修订暂停待办任务，则标记任务已打开
                if (row.applyStatus === '05') {
                    let params = {
                        businessNo: row.applyNo,
                    }
                    updateBackTaskIsOpen(params).then(res => {
                        if (res.code === "0000") {
                        }
                    });
                }
                let turn = "apply-report-edit" + row.applyNo;
                this.afs.newTab(this, 'projects/afs-apply/pages/apply-report/personal/index', '申请进件', 'ios-add',
                    {applyNo: row.applyNo, applyStatus: row.applyStatus, diffType: "edit"}, turn, [], true);
            },
            //刷新
            refresh() {
                this.$refs['loanApplyTable'].reloadData();
            },
            //刷新
            refreshUserData() {
                this.$refs['transferTable'].reloadData();
            },
            //重置表单数据,并重新加载数据
            handleReset() {
                this.searchStatus.condition.applyStatusList = [];
                this.$refs.loanApplyForm.resetFrom();
                this.refresh();
            },
            //撤回
            callBack(row) {
                this.$refs.backForm.updateFormData(row);
                this.backModalVisible = true;
            },
            queryOrderInfo(args) {
                let param = "";
                param = {
                    applyNo: args,
                };
                getOrderInfo(param).then(res => {
                    if (res.code === "0000") {
                        if (res.data.applyStatus === '00' || res.data.applyStatus === '13') {
                            this.refresh();
                            this.$Message.success("撤回成功");
                        } else {
                            this.$Message.warning("当前订单无法撤回");
                        }
                        this.loading = false;
                    }
                });
            },
            //复议
            reconsider(row) {
                this.$refs.reconsiderForm.updateFormData(row);
                // this.$refs.reconsiderForm.setAllFieldRequired(true);
                this.reconsiderModalVisible = true;
                let self = this;
                this.$nextTick(function () {
                    this.$refs.singleUpload.resetimgurl();
                    this.$refs.singleUpload.showCarImg(row.applyNo);
                })
            },
            //加急
            urgent(row) {
                this.$refs.urgentForm.updateFormData(row);
                // this.$refs.urgentForm.setAllFieldRequired(true);
                this.urgentModalVisible = true;
            },
            //转单
            transfers(row) {
                this.transferModalVisible = true;
                this.applyNo = row.applyNo;
                this.businessType = row.businessType;
                this.refreshUserData();
            },
            //复制
            copy(row) {
                this.$Modal.confirm({
                    title: "是否确认要复制该订单？",
                    onOk: () => {
                        saveCopy(row).then(res => {
                            if (res.code === "0000") {
                                this.$Message.success("复制成功");
                                this.refresh();
                            }
                        }).catch(() => {
                            this.refresh();
                        });
                    }
                });
            },
            //保存复议信息
            reconsiderSubmit() {
                this.$refs.reconsiderForm.getForm().validate((valid) => {
                    if (valid) {
                        //复议MQ
                        let params = {
                            applyNo: this.$refs.reconsiderForm.getFormData().applyNo,
                            reconsiderReason: this.$refs.reconsiderForm.getFormData().reconsiderReason,
                        }
                        this.queryImgParam(params);
                        // if (!data) {
                        //     this.$Message.warning("请上传复议资料");
                        //     return;
                        // }
                        saveReconsiderCaseSubmit(params).then(res => {
                            if (res.code === '0000') {
                                this.reconsiderModalVisible = false;
                                this.$Message.success("复议提交成功")
                                this.refresh();
                            }
                        })
                    }
                });
            },
            //获取图片入参数
            queryImgParam(params) {
                // 影像入参数
                let imgList = this.$refs.singleUpload.singleimglist();
                if (imgList.length < 1) {
                    return false;
                }
                if (imgList.length > 0) {
                    let tempArr = [];
                    imgList.forEach((item, index) => {
                        item.map.type = this.imgtype
                        tempArr.push(item.map);
                    })
                    params.contractFileVos = tempArr;
                }
                return true;
            },
            //保存加急信息
            urgentSubmit() {
                this.$refs.urgentForm.getForm().validate((valid) => {
                    if (valid) {
                        saveUrgent(this.$refs.urgentForm.getFormData()).then(res => {
                            if (res.code === "0000") {
                                this.sendForEmergencyCaseSubmit(this.$refs.urgentForm.getFormData().applyNo);
                                this.refresh();
                                this.urgentModalVisible = false;
                                this.urgentName = '已加急';
                            }
                        })
                    }
                });
            },
            //加急MQ
            sendForEmergencyCaseSubmit(v) {
                let params = {applyNo: v}
                sendForEmergencyCaseSubmit(params).then(res => {
                    if (res.code === '0000') {
                        this.$Message.success("加急成功");
                        this.count--;
                        if (this.count === 0) {
                            this.disable = true;
                        }
                    }
                })
            },

            //保存撤回信息
            backSubmit() {
                this.$refs.backForm.getForm().validate((valid) => {
                    if (valid) {
                        this.loading = true;
                        saveBack(this.$refs.backForm.getFormData()).then(res => {
                            if (res.code === "0000") {
                                this.sendCallbackApplyInfo(this.$refs.backForm.getFormData().applyNo);
                                this.refresh();
                                this.backModalVisible = false;
                            }
                            this.loading = false;
                        }).catch(() => {
                            this.loading = false;
                            this.backModalVisible = false;
                            this.refresh();
                        });
                    }
                });
            },
            //撤回MQ
            sendCallbackApplyInfo(v) {
                let params = {applyNo: v}
                sendForCallBackCaseSubmit(params).then(res => {
                    if (res.code === '0000') {
                        //延迟1.5秒查询状态是否已更新
                        setTimeout(() => {
                            this.loading = true;
                            this.queryOrderInfo(v);
                        }, 1500);
                    }
                })
            },
            //保存转单信息,需要转单用户，申请编号
            transferSubmit(row) {
                let params = {
                    createBy: row.username,
                    applyNo: this.applyNo,
                }
                this.businessType = row.businessType
                transferData(params).then(res => {
                    if (res.code === '0000') {
                        this.transferModalVisible = false;
                        this.$Message.success("转单成功")
                        this.refresh();
                    }
                });
            },
            getPageInfo() {
                return {
                    pageNumber: this.pageData.pageNumber,
                    pageSize: this.pageData.pageSize
                }
            },
            dropDown() {
                if (this.drop) {
                    this.dropDownContent = "更多筛选";
                    this.dropDownIcon = "ios-arrow-down";
                } else {
                    this.dropDownContent = "收起筛选";
                    this.dropDownIcon = "ios-arrow-up";
                }
                this.drop = !this.drop;
            },

            // 获取当前登录用户的权限
            getUserPower() {
                getUserPower().then(res => {
                    if (res.code === "0000") {
                        console.log(res.data.userManage)
                        this.userPower.userManage = res.data.userManage;
                        this.userPower.userId = res.data.userId;
                        this.userPower.newApplyPower = res.data.newApplyPower;
                        this.userPower.odlApplyPower = res.data.odlApplyPower;
                        this.userPower.newAccountPower = res.data.newAccountPower;
                        this.userPower.oldAccountPower = res.data.oldAccountPower;
                        console.log(this.userPower)
                    }
                });
            },
        }
    }
</script>
<style scoped lang="less">
    .loanApplyMng {

        .uploadecn {
            padding-left: 150px;
        }

        .uploadecn > span {
            width: 150px;
            position: absolute;
            top: 0px;
            left: 0px;
            color: #333;
            text-align: right;
            padding-right: 12px;
        }

        /deep/ .ivu-table .demo-table-05-row td {
            background-color: #f5a623;
            color: #fff;
        }

        /deep/ .ivu-table .demo-table-error-row td {
            background-color: #ff6600;
            color: #fff;
        }

        .loanApplyBtn .ivu-btn:focus {
            color: #efab4d;
            background-color: white;
            border-color: #efab4d;
            box-shadow: none;
        }

    }

</style>
<style lang="less" scoped>
    @import "../../assets/css/applyList.less";
</style>
